using System;
using System.Collections.Generic;
using System.Linq;

namespace CML.Intercamber.Business.Dao
{
    public class ThreadActionsDao
    {
        public List<ThreadActions> ListThreadMessagesByParameters(long idThread)
        {
            List<ThreadActions> res;
            using (var context = new IntercamberEntities())
            {
                DateTime maxDate = DateTime.Now.AddDays(-1);
                var req = context.ThreadActions.Where(x => x.IdThread == idThread && x.DateAction > maxDate).OrderByDescending(x => x.DateAction);
                res = req.OrderByDescending(x => x.DateAction).ToList();
            }
            return res;
        }

        public long InsertThreadActions(ThreadActions obj)
        {
            using (var context = new IntercamberEntities())
            {
                context.ThreadActions.Add(obj);
                context.SaveChanges();
            }
            return obj.IdAction;
        }

    }
}

